#include("_layout.html")
#@layout()
#define layoutImportcss()
#end
#define layoutHead()
	<title>学生信息</title>
#end
#define layoutHome()

<div class="page-content patriarch-page-content">
	<div class="navbar">
		<div class="navbar-inner toolbstyle">
			<div class="left">
				<a id="a_back" class="link external back" href="javascript:history.back()">
					<i class="icon icon-back"></i>
				</a>
			</div>
			<div class="title" id="navbar_title">学生信息</div>
			<div class="right"></div>
		</div>
	</div>
	
<form id="my-form">
	<input type="text" id="student_id" name="student_id" value="" style="width:0px; height:0px;">
	<div class="list">
		<ul>
			<li>
				<div class="item-content">
					<div class="item-inner">
						<span class="head-portrait head-portrait60">
							<img id="user_head_img" src="/front/img/user.png">
						</span>
						<a id="a_user_head" class="item-value user-head external" style="text-align: right; position: absolute;">修改头像
							<input type="file" id="file_user_head" multiple style="width:0px; height: 0px;">
						</a>
					</div>
				</div>
			</li>
			<li>
				<a class="item-link a_edit_words">
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title">姓名</div>
							<div class="item-value" id="student_name_lab">点击输入</div>
							<input type="hidden" id="student_name" name="student_name" value="">
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link smart-select smart-select-init" data-open-in="sheet" data-close-on-select="true" data-sheet-close-link-text="完成">
					<select id="class_id" name="class_id">
						<option value="">请选择</option>
					</select>
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title post_name">班级</div>
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link a_edit_words">
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title">学号</div>
							<div class="item-value" id="student_sno_lab"></div>
							<input type="hidden" id="student_sno" name="student_sno" value="">
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link smart-select smart-select-init" data-open-in="sheet" data-close-on-select="true" data-sheet-close-link-text="完成">
					<select id="sex_id" name="sex_id">
						<option value="">请选择</option>
						<option value="1">男</option>
						<option value="2">女</option>
					</select>
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title post_name">性别</div>
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link a_edit_words">
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title">生日</div>
							<div class="item-value" id="student_birthday_lab">点击输入</div>
							<input type="hidden" id="student_birthday" name="student_birthday" value="" data-model="date">
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link a_edit_words">
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title">入学日期</div>
							<div class="item-value" id="join_date_lab">点击输入</div>
							<input type="hidden" id="join_date" name="join_date" value="" data-model="date">
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link a_edit_words">
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title">身份证号</div>
							<div class="item-value" id="student_carno_lab">点击输入</div>
							<input type="hidden" id="student_carno" name="student_carno" value="">
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link a_edit_words">
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title">联系电话</div>
							<div class="item-value" id="student_mobile_lab"></div>
							<input type="hidden" id="student_mobile" name="student_mobile" value="">
						</div>
					</div>
				</a>
			</li>
			<li>
				<a class="item-link a_edit_words">
					<div class="item-content">
						<div class="item-inner">
							<div class="item-title">家庭住址</div>
							<div class="item-value" id="home_address_lab">点击输入</div>
							<input type="hidden" id="home_address" name="home_address" value="">
						</div>
					</div>
				</a>
			</li>
		</ul>
	</div>
	</form>
	<div><button id="btn_all_sub" class="button button-fill botton-width" style="margin-top: 10px;">提交更新</button></div>
</div>

<div class="popup popup-edit-words">
    <div class="block">
		<div class="row">
			<div class="col-33">
				<a class="link popup-close" href="#">取消</a>
			</div>
			<div class="col-33" style="text-align: center;" id="popup_title">编辑文字</div>
			<div class="col-33" style="text-align: right;">
				<a id="popup_btn_ok" href="#">确定</a>
			</div>
		</div>
      <p>
		  <input id="popup_target" type="hidden">
		  <textarea id="popup_text" rows="30" style="width:100%; height: 90%; border: 1px solid #ccc;"></textarea>
		  <div id="popup_calendar" style="display:none;"></div>
		  <div id="popup_upload" style="display:none; width:345px; height:120px;">
			  <img id="popup_upload_img" src="" style="display: none; width:345px; height:120px;">
			  <button id="popup_upload_btn" class="col button button-outline">上传文件</button>
			  <input type="file" id="file_popup_upload" multiple style="width:0px; height: 0px;">
		  </div>
	  </p>
    </div>
</div>

#end
#define layoutImportjs()
#end
#define layoutScript()
<script type="text/javascript">
	var stu_id = getUrlParam('stuid');
	$$('#student_id').val(stu_id);
	/**日期控件**/
	var calendarInline = app.calendar.create({
	  containerEl: '#popup_calendar',
	  value: [new Date()],
	  weekHeader: true,
	  monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
	  dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
	  on: {
		dayClick: function(calendar, dayEl, year, month, day){
			var strdate = year + '-' + (month+1) + '-' + day;
			console.log(strdate);
			$$('#popup_text').val(strdate);
			popup_btn_ok_click();
		}
	  }
	});
	/**日期控件**/
	/**初始化数据**/
	sendPost('/front/teacher/students/getStudent?stuid='+stu_id, null, function(res){
		//console.log(res);
		if (res.code == 200){
			$$('#user_head_img').attr('src', formatUserHeadImage(res.studata.student_headpic));
			
			var shtml = '';
			for(var i=0; i<res.listclass.length; i++){
				var jdata = res.listclass[i];
				shtml += '<option value="'+jdata.class_id+'">'+jdata.class_name+'</option>';
			}
			$$('#class_id').append(shtml);
			
			setFormData(res.studata);
			
		}
	});
	function setFormData(formData){
		app.form.fillFromData('#my-form', formData);
		var els = $$('input[type="hidden"]');
		for(var i=0; i<els.length; i++){
			var el_id = $$(els[i]).attr('id');
			var el_val = $$(els[i]).val();
			var dmodel = $$('#'+el_id).attr('data-model');
			
			if(dmodel == 'image'){ 
				if (!isBlank(el_val)){ $$('#'+el_id+'_lab').html(el_val.substr(el_val.lastIndexOf('/'))); }
			}else if(dmodel == 'date'){ 
				if (!isBlank(el_val)){ $$('#'+el_id+'_lab').html(formatDate(el_val, 'yyyy-MM-dd')); }
			}else if (dmodel == 'text'){ 
				if (!isBlank(el_val)){ 
					var strv = el_val.length>8 ? el_val.substr(0,8)+'..' : el_val;
					$$('#'+el_id+'_lab').html(strv); }
			}else{ 
				$$('#'+el_id+'_lab').html(el_val);
			}
		}
	}
	/**初始化数据**/
	/**更多资料开关**/
	var showMoreInfo = 0;
	$$('#a_btn_more').on('click', function(){
		
		if (showMoreInfo == 0){ showMoreInfo = 1; $$('.more-myinfo').show(); 
			$$('#a_btn_more').find('.item-title').text('选填信息，见下');}
		else{ showMoreInfo = 0; $$('.more-myinfo').hide();$$('#a_btn_more').find('.item-title').text('更多资料'); }
	});
	/**更多资料开关**/
	
	/**弹出窗口**/
	$$('a.a_edit_words').on("click", function(){
		var inp_id = $$(this).find('input[type="hidden"]').attr('id');
		var inp_title = $$(this).find('div.item-title').text();
		showPopupPanel(inp_id, inp_title);
	});
	function showPopupPanel(inp_id, inp_title){
		var val_txt = $$('#'+inp_id).val();
		$$('#popup_target').val(inp_id);
		$$('#popup_title').text('编辑'+inp_title);
		$$('#popup_text').val(val_txt);
		
		var dmodel = $$('#'+inp_id).attr('data-model');
	
		$$('#popup_text').hide();
		$$('#popup_calendar').hide();
		$$('#popup_upload').hide();
		
		if (!isNull(dmodel) && dmodel == 'date'){
			$$('#popup_calendar').show();
		}else if (!isNull(dmodel) && dmodel == 'image'){
			$$('#popup_upload').show();
			if (!isBlank(val_txt)){
				$$('#popup_upload_img').attr('src', getZoomFileUrlwh(val_txt, 340, 120)).show();
			}
		}else{
			$$('#popup_text').show();
			$$('#popup_text').focus();
		}
		app.popup.open($$('div.popup-edit-words'));
	}
	$$('#popup_btn_ok').on('click', function(){
		popup_btn_ok_click();
	});
	function popup_btn_ok_click(){
		var inp_id = $$('#popup_target').val();
		var val_txt = $$('#popup_text').val();
		$$('#'+inp_id).val(val_txt);
		
		var dmodel = $$('#'+inp_id).attr('data-model');
			
		if(dmodel == 'date'){ 
			$$('#'+inp_id+'_lab').html(val_txt); 
		}else if(dmodel == 'image'){ 
			if (!isBlank(val_txt)){ $$('#'+inp_id+'_lab').html(val_txt.substr(val_txt.lastIndexOf('/'))); }
		}else if (dmodel == 'text'){  
				if (!isBlank(val_txt)){ 
					var strv = val_txt.length>8 ? val_txt.substr(0,8)+'..' : val_txt;
					$$('#'+inp_id+'_lab').html(strv); }
		}else{ 
			$$('#'+inp_id+'_lab').html(val_txt); 
		}
		app.popup.close($$('div.popup-edit-words'));
	}
	$$('#popup_upload_btn').on("click", function(){
		$$("#file_popup_upload").click();
	});
	$$("#file_popup_upload").on("change", function(e){
		var file = e.target.files[0],
        reader = new FileReader();
		reader.readAsDataURL(file);
		reader.onload = function (ev) {
			if (checkUploadFile(file, 'images')){
				photo = ev.target.result //获取图片内容：base64字符串
				var formdata = { filename: file.name, 
								 filesize: file.size, 
								 filetype: '.'+file.type.split("/")[1], 
								 base64_data: photo };
								 
				sendPost('/front/teacher/fileup/upload_base64?w=340&h=120', formdata, function(res){
					//console.log(res);
					if (res.code == 0){
						$$('#popup_upload_img').attr("src", photo).show();
						$$('#popup_text').val(res.fileurl);
					}else{
						alert(res.msg);
					}
				});
			}
		};
	});
	
	/**弹出窗口**/
	/**图片上传**/	
	$$('#a_user_head').on("click", function(){
		$$("#file_user_head").click();
	});
	$$("#file_user_head").on("change", function(e){
		var file = e.target.files[0],
        reader = new FileReader();
		reader.readAsDataURL(file);
		reader.onload = function (ev) {
			if (checkUploadFile(file, 'images')){
				photo = ev.target.result //获取图片内容：base64字符串
				var formdata = { filename: file.name, 
								 filesize: file.size, 
								 filetype: '.'+file.type.split("/")[1], 
								 base64_data: photo };
								 
				sendPost('/front/teacher/students/upload_stuhead?stuid='+stu_id, formdata, function(res){
					//console.log(res);
					if (res.code == 0){
						$$('.head-portrait-big img').attr("src", photo);
					}else{
						alert(res.msg);
					}
				});
			}
		};
	});
	/**图片上传**/	
	/**保存**/	
	$$("#btn_all_sub").on("click", function(){
	    var formData = app.form.convertToData('#my-form');
		sendPost('/front/teacher/students/update_info', formData, function(res){
			alert(res.msg);
			if (res.code == 200){
				
			}
		});
	});
	/**保存**/	
</script>
#end